import { request } from '../../utils/request'
import store from '../../store'
const loginAPI = ({ mobile, code }) => {
  return request({
    url: '/v1_0/authorizations',
    method: 'POST',
    data: {
      mobile,
      code
    }
  })
}
const userInfoAPI = () => {
  return request({
    url: '/v1_0/user'
  })
}
// 编辑资料
const userProfileAPI = () => {
  return request({
    url: '/v1_0/user/profile'
  })
}
// 更换头像
const updatePhotoAPI = ({ from }) => {
  return request({
    url: '/v1_0/user/photo',
    method: 'PATCH',
    data: from
  })
}
// 修改名称
const updateProfileAPI = ({ birthday, userName }) => {
  return request({
    url: '/v1_0/user/profile',
    method: 'PATCH',
    data: {
      birthday,
      userName
    }
  })
}
// 续签token
const refreshTokenAPI = () => {
  return request({
    url: '/v1_0/authorizations',
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${store.state.refresh_token}`
    }
  })
}
export {
  loginAPI,
  userInfoAPI,
  userProfileAPI,
  updatePhotoAPI,
  updateProfileAPI,
  refreshTokenAPI
}
